<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>JS小练习</title>
  <style>
    body {
      background-color: lightgoldenrodyellow;
      transition: .8s;
    }

    .box {
      width: 300px;
      position: absolute;
      left: 50%;
      top: 50%;
      transform: translate(-50%, -50%);
    }

    .box>img {
      width: 100%;
      cursor: pointer;
      border-radius: 15px;
    }
  </style>
</head>

<body>
  <div class="box">
    <img src="./img/show.svg" alt="">
  </div>
</body>
<script>
  const oBody = document.querySelector('body')
  const oImg = document.querySelector('img')
  const url = ['./img/show.svg', './img/hide.svg']
  const bgc = ['lightgoldenrodyellow', '#333']
  let light = false
  oImg.onclick = function () {
    oBody.style.backgroundColor = light ? bgc[0] : bgc[1]
    this.src = light ? url[0] : url[1]
    light = !light
  }
</script>

</html>